package com.lkpstudy.rbac.mapper;

import com.lkpstudy.rbac.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
* @author likaiping
* @description 针对表【role(角色表)】的数据库操作Mapper
* @createDate 2024-04-17 20:25:23
* @Entity com.lkpstudy.rbac.entity.Role
*/
public interface RoleMapper extends BaseMapper<Role> {
    /**
     * 根据角色id删除其所有权限
     * @param roleId 角色id
     * @return
     */
    @Delete("DELETE FROM role_auth WHERE role_id=#{roleId}")
    boolean deleteAuthsByRoleId(@Param("roleId") Long roleId);

    /**
     * 根据角色id给其添加权限
     * @param roleId 角色id
     * @param authIds 需要添加的权限id列表
     * @return
     */
    @Insert("<script>" +
            "INSERT INTO role_auth(role_id,auth_id) VALUES " +
            "<foreach collection='authIds' item='item' separator=',' >" +
            "   (#{roleId},#{item})" +
            "</foreach>" +
            "</script>")
    boolean insertAuthsBatch(@Param("roleId") Long roleId,@Param("authIds") List<Long> authIds);
}




